/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package fr.unice.miage.entities;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;

/**
 *
 * @author remi jeremy
 */
@Entity
public class CompteBanquaire implements Serializable {
    private static final long serialVersionUID = 1L;
    
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    private String titre;
    private float solde;
    private String numero;
    @ManyToOne
    private Utilisateur proprietaire;
    
    @OneToMany(fetch= FetchType.LAZY)
    private Collection<OperationBanquaire> operations;

    public CompteBanquaire() {}
    
    public CompteBanquaire(Utilisateur proprietaire,String titre, float solde, String numero)
    {
        this.titre = titre;
        this.solde = solde;
        this.proprietaire = proprietaire;
        this.numero = numero;
    }
    
    public Utilisateur getProprietaire()
    {
        return proprietaire;
    }
    
    public void setProprietaire(Utilisateur proprietaire)
    {
        this.proprietaire = proprietaire;
    }

    public String getTitre() {
        return titre;
    }

    public void setTitre(String titre) {
        this.titre = titre;
    }

    public float getSolde() {
        return solde;
    }

    public void setSolde(float solde) {
        this.solde = solde;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }
    
    public Collection<OperationBanquaire> getOperations() {
        return operations;
    }
     
    public Collection<OperationBanquaire> addOperation(OperationBanquaire ob)
    {
        this.operations.add(ob);
        return this.operations;
    }

    public String getNumero() {
        return numero;
    }

    public void setNumero(String numero) {
        this.numero = numero;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof CompteBanquaire)) {
            return false;
        }
        CompteBanquaire other = (CompteBanquaire) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id)) ) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "fr.unice.miage.entities.CompteBanquaire[ id=" + id + " ]";
    }
    
    
    
    /* Additional Methods */
    public float retirerArgent(float argent)
    {
        this.solde -= argent;
        return this.solde;
    }
    
    public float deposerArgent(float argent)
    {
        this.solde += argent;
        return this.solde;
    }
    
    public float ajouterArgent(float argent)
    {
        this.solde += argent;
        return this.solde;
    }
    
}
